# -*- coding: utf-8 -*-
# Created by zhangyanqi on 2018/4/7
"""
leetcod 128题
最长连续子列

思路：
排序，然后进行判断

"""


class Solution:
    def longestConsecutive(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if not nums:
            return 0

        nums.sort()

        longest_streak = 1
        current_streak = 1

        for i in range(1, len(nums)):
            if nums[i] != nums[i - 1]:
                if nums[i] == nums[i - 1] + 1:
                    current_streak += 1
                else:
                    longest_streak = max(longest_streak, current_streak)
                    current_streak = 1

        return max(longest_streak, current_streak)


if __name__ == "__main__":
    s = Solution()
    consecutive = s.longestConsecutive([0, 2, -1, 1, 4])
    print(consecutive)
